<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('线下付款申请')" />
    <th:block th:include="include :: businessCSS" />
	<style>
		.layui-table-tool-self{display: none;}
		.layui-table-tool-temp{padding-right:0}
	</style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
		<form class="layui-form head-form">
		    <div class="north">
                <th:block th:include="include :: business_btn" />
	        	<th:block th:include="include :: business_tpl('top')" />
	    	</div>
		    <div class="mid-content">
		        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
		    </div>
			<th:block th:include="include :: pageFooter" />
		</form>

	</div>
</div>
<script type="text/html" id="toolbar">
	<div style="padding: 16px;display: flex;justify-content: space-between;">
		<div  style="font-weight: 700;font-size: 18px;">线下订单</div>
		<div>
			<button class="layui-btn layui-btn-normal dhicon"  type="button"  lay-event="addbtn" id="btn-sh">新增</button>
			<!-- <button class="layui-btn layui-btn-danger dhicon"  type="button" th:disabled="${enableEdit} == 1 ?false:true" lay-event="mjbtn_save" id="btn-sh">删除</button> -->
		</div>
	</div>
</script>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<th:block th:include="include :: inlineJS" />
<script type="text/javascript">
var $,layer,form,table,laydate,element;//定义layui模块
var listData1 = [];
eachFields();//明细表格中的字段遍历


if(!!$("#fXsFpsl_select").val())$("#fXsFpsl").val($("#fXsFpsl_select").val());//默认税率赋值至input
layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();
 	$.get(moduleUrl+"/listbynid?nid="+nid,function(data){
		$.each(data.data,function(k,v){
			dataStr.push(v);
		});
		listData1 = data.data
		// numall()
		initTable();//初始化表格
	});
	toolbarEvent();//通用表格头部工具栏事件监听
	toolEvent('ftable');//行event事件监听
	monitorSort();//监听排序——重载赋值渲染

	//监听单元格编辑
	table.on('edit(ftable)', function(obj){
		// console.log(88899)
		
		var cost2 = obj.data.sum * obj.data.price2
		var serviceCharge = (+(obj.data.freightCharge) + (+cost2))*0.05
		obj.update({orderAmount:cost2,cost2:cost2,serviceCharge:serviceCharge.toFixed(2)});
		// numall()
	});


	table.on('toolbar(ftable)', function (obj) {
            var selectedObject=""
            table.cache.dhtable.map((v,i)=>{
                if(selectedObject){
                    selectedObject+=','+v.pGuid
                }else{
                    selectedObject+=v.pGuid
                }
            })
            switch (obj.event) {
                case 'addbtn':
                if(!$('#partnerId').val()){
                    layer.msg('请先选择供应商')
                    return;
                }
                sessionStorage.setItem('partnerId',$('#partnerId').val())
                
			    layer.open({
                	type: 2,
                	area: [($(window).width() - 200)+'px', ($(window).height() - 100)+'px'],
                	fix: false,//不固定
                	offset: '10%',//距离顶部
                	maxmin: true,//最大最小化
                	shade: 0.3,//遮罩
                	title: '采购列表',
                	content: "/purchase/purchaseplan/select2?pagetype=checkbox&by=direct&fmoduleTable="+moduleTable+"&selectedObject="+selectedObject,
                	btn: ['确定', '取消'],
                	shadeClose: true,// 弹层外区域关闭
                	yes: function(index, layero){
                		console.log('click---yes');
						var res = window["layui-layer-iframe" + index].callbackdata();
				        if(res.length > 0){
							var bidstr=""
				        	$.each(res,function(i,v){
								if(bidstr){
                                    bidstr+=','+v.bid
                                }else{
                                    bidstr+=v.bid
                                }
								v.unpaidAmount = v.cost2 - v.amountPaid
                                v.orderID=v.bid
                                v.vDFilesDefault=''
                                v.vDFilesFP=''
                                v.vBz=''
                                v.guid=''

				        	})
							layer.closeAll();
                            table.reload('dhtable', {data:res,limit:res.length});

				        }else{
                            layer.msg("请选择数据");
                        }
                	}
                });

                   break;
    
                case 'mjbtn_save':
                    var objdata=table.checkStatus('dhtable')
                    objdata=objdata.data
                    listData1= table.cache.dhtable;
                    if(objdata.length>0){
                        objdata.forEach(item => {
                            listData1 = listData1.filter(items => items.guid!= item.guid);
                        });
                        table.reload('dhtable', {data:listData1});
                    }else{
                        layer.msg("请选择数据");
                    }
                    break;
            };
        });




})


</script>
</body>
</html>
